home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5775 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  57 lines

  1. Path: alterdial.uu.net!not-for-mail
  2. From: rogerst@approach.com (Tom Rogers)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: String Arrays and string parsing
  5. Date: Tue, 20 Feb 1996 20:31:07 GMT
  6. Message-ID: <4gd0ik$6bs@alterdial.UU.NET>
  7. References: <31287278.789445@news.inforamp.net> <4gaqrj$3kn@hacgate2.hac.com>
  8. NNTP-Posting-Host: 198.177.211.32
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. collins@thor.tu.hac.com (Ron Collins) wrote:
  12.  
  13.  
  14. >You've almost got it with the "strncpy()".  Try this:
  15. >(assuming you define "from1" somewhere)
  16.  
  17. >#include <string.h>
  18.  
  19. >....
  20.  
  21. >char  into1[3];
  22. >char  into2[4];
  23. >char  into3[5];
  24.  
  25. >...
  26.  
  27. >   strncpy(into1,from1,2);
  28. >   into1[2] = 0;
  29. >   strncpy(into2,from1+2,3);
  30. >   into2[3] = 0;
  31. >   strncpy(into3,from1+5,4);
  32. >   into3[4] = 0;
  33.  
  34. Ron, for clarities sake, you really ought to terminate your strings
  35. with '\0' chars rather than 0's.  A nit, I know, since they are the
  36. same, but it is much easier for beginners and maintainers to
  37. see that you are null terminating a string....
  38.  
  39. Regards,
  40. Tom
  41.  
  42. >This will place the proper substrings into the "intoX" arrays.
  43.  
  44.  
  45.  
  46. >                        -- Collins --
  47. >                        
  48. >-----
  49. >The views expressed here are mine alone.
  50.  
  51. >Ron Collins/Hughes Aircraft Company/M20,P20/Tucson Az 85706
  52. >rcollins@thor.tu.hac.com    collins@seagull.rtd.com
  53. >ยก----
  54.  
  55.  
  56.  
  57.